const express = require('express');
const db = require('./db');//会自动查找index.js
const bookRouter = require('./routers/bookRouter');
db(() => {
    console.log('数据库连接成功');
    const app = express();

    // 使用中间件 静态资源，body-parse,路由器
    app.use(express.static('public'));
    app.use(express.urlencoded({extended: false}));
    app.use(express.json());
    app.use('/book', bookRouter);

    // 使用ejs
    app.set('view engine', 'ejs');
    app.set('views', './views');

    // 启动web服务
    app.listen('8989', () => {
        console.log('服务已启动','http://localhost:8989');
    })

}, () =>{
    console.log('数据库连接失败');
})